<?php
require_once("clases/funciones_bd.php");
require_once("clases/sesion.class.php");
ob_start();
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>TermosApp</title>
    
    <!-- Core CSS - Include with every page -->
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="font-awesome/css/font-awesome.css" rel="stylesheet">

    <!-- SB Admin CSS - Include with every page -->
    <link href="css/sb-admin.css" rel="stylesheet">
</head>

<body>

    <div class="container">
        <div class="row">
            <div class="col-md-4 col-md-offset-4">
                <div class="login-panel panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title">Por favor Inicie sesión</h3>
                    </div>
                    <div class="panel-body">
                    <?php
					$sesion = new sesion();
                    if( isset($_POST["iniciar"]) ){
					$usuario = $_POST['usuario'];
					$passw = $_POST['password'];
					$db = new funciones_BD();
					$user = $db->login($usuario,$passw);
						if($db->login($usuario,$passw)){		
							echo '<div class="alert alert-danger">
									Este usuario no esta registrado en la base de datos.
								  </div>';
						}else{
							$sesion->set("usuario",$usuario);
							$sesion->set("idusuario", $user[0]);
							header("location: principal.php");
						}
                    }
                    ?>
                        <form role="form" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
                            <fieldset>
                                <div class="form-group">
                                    <input class="form-control" placeholder="usuario" name="usuario" 
                                    type="usuario" autofocus>
                                </div>
                                <div class="form-group">
                                    <input class="form-control" placeholder="password" name="password" 
                                    type="password" value="">
                                </div>
                                <div class="checkbox">
                                    <label>
                                        <input name="remember" type="checkbox" value="Remember Me">Recordar Usuario
                                    </label>
                                </div>
                                <!-- Change this to a button or input when using this as a form -->
                                <input type="submit" name="iniciar" class="btn btn-lg btn-success btn-block" 
                                value="Iniciar Sesión" />
                            </fieldset>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Core Scripts - Include with every page -->
    <script src="js/jquery-1.10.2.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/plugins/metisMenu/jquery.metisMenu.js"></script>

    <!-- SB Admin Scripts - Include with every page -->
    <script src="js/sb-admin.js"></script>

</body>

</html>
